package grape.wx.rest.mp.reply.mvc;

import com.baomidou.mybatisplus.core.metadata.IPage;
import grape.wx.service.mp.MpProperties;
import grape.wx.service.mp.reply.query.MpMsgReplyListQuery;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import javax.validation.Valid;
import grape.wx.rest.mp.reply.form.MpMsgReplyCreateForm;
import grape.wx.rest.mp.reply.form.MpMsgReplyUpdateForm;
import grape.wx.rest.mp.reply.form.MpMsgReplyListPageForm;
import grape.wx.rest.mp.reply.vo.MpMsgReplyVo;
import grape.wx.rest.mp.reply.mapper.MpMsgReplyWebMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;
import grape.common.rest.mvc.BaseController;
import grape.wx.service.mp.reply.po.MpMsgReply;
import grape.wx.service.mp.reply.api.IMpMsgReplyService;

/**
 * <p>
 * 公众号消息回复表 前端控制器
 * </p>
 *
 * @author yangwei
 * @since 2020-07-23
 */
@RestController
@RequestMapping("/wx/mpmsgreply")
@Api(tags = "公众号消息回复表相关接口")
public class MpMsgReplyController extends BaseController<MpMsgReplyVo, MpMsgReply> {

    @Autowired
    private MpMsgReplyWebMapper currentWebMapper;
    @Autowired
    private IMpMsgReplyService currentService;
    @Autowired
    private MpProperties mpProperties;



     @ApiOperation("添加公众号消息回复表")
     @PreAuthorize("hasAuthority('mpmsgreply:single:create')")
     @PostMapping
     @ResponseStatus(HttpStatus.CREATED)
     public MpMsgReplyVo create(@RequestBody @Valid MpMsgReplyCreateForm cf) {
         MpMsgReply po = currentWebMapper.formToPo(cf);
         po.setAppName(mpProperties.abtainAppNameByAppCodeOrAppId(po.getAppCode()));
         return super.create(po);
     }

     @ApiOperation("根据ID查询公众号消息回复表")
     @PreAuthorize("hasAuthority('mpmsgreply:single:queryById')")
     @GetMapping("/{id}")
     @ResponseStatus(HttpStatus.OK)
     public MpMsgReplyVo queryById(@PathVariable String id) {
         return super.queryById(id);
     }

     @ApiOperation("删除公众号消息回复表")
     @PreAuthorize("hasAuthority('mpmsgreply:single:deleteById')")
     @DeleteMapping("/{id}")
     @ResponseStatus(HttpStatus.NO_CONTENT)
     public boolean deleteById(@PathVariable String id) {
         return super.deleteById(id);
     }

     @ApiOperation("更新公众号消息回复表")
     @PreAuthorize("hasAuthority('mpmsgreply:single:updateById')")
     @PutMapping("/{id}")
     @ResponseStatus(HttpStatus.CREATED)
     public MpMsgReplyVo update(@PathVariable String id,@RequestBody @Valid MpMsgReplyUpdateForm uf) {
         MpMsgReply po = currentWebMapper.formToPo(uf);
         po.setId(id);
         po.setAppName(mpProperties.abtainAppNameByAppCodeOrAppId(po.getAppCode()));
         return super.update(po);
     }

    @ApiOperation("分页查询公众号消息回复表")
    @PreAuthorize("hasAuthority('mpmsgreply:single:listPage')")
    @GetMapping("/listPage")
    @ResponseStatus(HttpStatus.OK)
    public IPage<MpMsgReplyVo> listPage(MpMsgReplyListPageForm listPageForm) {
         MpMsgReply po = currentWebMapper.formToPo(listPageForm);
        MpMsgReplyListQuery mpMsgReplyListQuery = new MpMsgReplyListQuery();
        mpMsgReplyListQuery.setPoQuery(po);
        return super.listPage(mpMsgReplyListQuery,listPageForm);
     }

}
